package com.ruoyi.project.channel.vwChannelPayTypeDayStat.controller;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.channel.payerPayType.domain.PayerPayType;
import com.ruoyi.project.channel.payerPayType.service.IPayerPayTypeService;
import com.ruoyi.project.channel.vwChannelQrCashDayStat.domain.VwChannelQrCashDayStat;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.vwChannelPayTypeDayStat.domain.VwChannelPayTypeDayStat;
import com.ruoyi.project.channel.vwChannelPayTypeDayStat.service.IVwChannelPayTypeDayStatService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * VIEW信息操作处理
 * 
 * @author CAIN
 * @date 2019-08-08
 */
@Controller
@RequestMapping("/channel/vwChannelPayTypeDayStat")
public class VwChannelPayTypeDayStatController extends BaseController
{
    private String prefix = "channel/view";
	
	@Autowired
	private IVwChannelPayTypeDayStatService vwChannelPayTypeDayStatService;
	@Autowired
	private IPayerPayTypeService payerPayTypeService;
	@Autowired
	private IUserService userService;
	@RequiresPermissions("channel:vwChannelPayTypeDayStat:view")
	@GetMapping()
	public String vwChannelPayTypeDayStat(ModelMap mmap)
	{
		PayerPayType search = new PayerPayType();
		search.setPayerUserName("系统自带");
		List<PayerPayType> payerPayTypes = payerPayTypeService.selectPayerPayTypeList(search);
		mmap.put("payerPayTypes", payerPayTypes);
		mmap.put("channels", userService.selectChannelList(new User()));
	    return prefix + "/vwChannelPayTypeDayStat";
	}
	
	/**
	 * 查询VIEW列表
	 */
	@RequiresPermissions("channel:vwChannelPayTypeDayStat:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(VwChannelPayTypeDayStat vwChannelPayTypeDayStat)
	{
		startPage();
		User user = getSysUser();
		String roleKey = ShiroUtils.getSysUser().getRoles().get(0).getRoleKey();
		List<VwChannelPayTypeDayStat> list = new ArrayList<>();
		if (roleKey.equals("channel")) {
			vwChannelPayTypeDayStat.setUserId(user.getUserId());
			list = vwChannelPayTypeDayStatService.selectVwChannelPayTypeDayStatList(vwChannelPayTypeDayStat);
		} else if (roleKey.equals("admin") || roleKey.equals("admin2")) {
			list = vwChannelPayTypeDayStatService.selectVwChannelPayTypeDayStatList(vwChannelPayTypeDayStat);
		}
		return getDataTable(list);
	}
	
	
	/**
	 * 导出VIEW列表
	 */
	@RequiresPermissions("channel:vwChannelPayTypeDayStat:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VwChannelPayTypeDayStat vwChannelPayTypeDayStat)
    {
		User user = getSysUser();
		String roleKey = ShiroUtils.getSysUser().getRoles().get(0).getRoleKey();
		List<VwChannelPayTypeDayStat> list = new ArrayList<>();
		if (roleKey.equals("channel")) {
			vwChannelPayTypeDayStat.setUserId(user.getUserId());
			list = vwChannelPayTypeDayStatService.selectVwChannelPayTypeDayStatList(vwChannelPayTypeDayStat);
		} else if (roleKey.equals("admin") || roleKey.equals("admin2")) {
			list = vwChannelPayTypeDayStatService.selectVwChannelPayTypeDayStatList(vwChannelPayTypeDayStat);
		}
        ExcelUtil<VwChannelPayTypeDayStat> util = new ExcelUtil<VwChannelPayTypeDayStat>(VwChannelPayTypeDayStat.class);
        return util.exportExcel(list, "vwChannelPayTypeDayStat");
    }
	
	/**
	 * 新增VIEW
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存VIEW
	 */
	@RequiresPermissions("channel:vwChannelPayTypeDayStat:add")
	@Log(title = "VIEW", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(VwChannelPayTypeDayStat vwChannelPayTypeDayStat)
	{		
		return toAjax(vwChannelPayTypeDayStatService.insertVwChannelPayTypeDayStat(vwChannelPayTypeDayStat));
	}

	/**
	 * 修改VIEW
	 */
	@GetMapping("/edit/{userId}")
	public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
	{
		VwChannelPayTypeDayStat vwChannelPayTypeDayStat = vwChannelPayTypeDayStatService.selectVwChannelPayTypeDayStatById(userId);
		mmap.put("vwChannelPayTypeDayStat", vwChannelPayTypeDayStat);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存VIEW
	 */
	@RequiresPermissions("channel:vwChannelPayTypeDayStat:edit")
	@Log(title = "VIEW", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(VwChannelPayTypeDayStat vwChannelPayTypeDayStat)
	{		
		return toAjax(vwChannelPayTypeDayStatService.updateVwChannelPayTypeDayStat(vwChannelPayTypeDayStat));
	}
	
	/**
	 * 删除VIEW
	 */
	@RequiresPermissions("channel:vwChannelPayTypeDayStat:remove")
	@Log(title = "VIEW", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(vwChannelPayTypeDayStatService.deleteVwChannelPayTypeDayStatByIds(ids));
	}
	
}
